package com.jenvin.btrace;

import java.lang.reflect.Field;

import com.sun.btrace.BTraceUtils;
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;
import com.sun.btrace.annotations.Self;

/**
 * Hello world!
 *
 */
@BTrace
public class App {
    @OnMethod(clazz = "+com.taobao.spuevolution.vo.product.ProductDO", method = "getSpuDO", location = @Location(value = Kind.ENTRY))
    public static void m(@Self Object self, @ProbeClassName String pcm, @ProbeMethodName String pmn) { // all
        BTraceUtils.println(strcat("Context: ", strcat(pcm, Strings.strcat("#", pmn))));
        BTraceUtils.println(self);

        Field spuDOField = field("com.taobao.spuevolution.vo.product.ProductDO", "spuDO");
        Object spuDo = get(spuDOField, self);

        Field statusField = field("com.taobao.item.domain.spu.StatusDO", "status");
        Field idField = field("com.taobao.item.domain.spu.SpuDO", "id");
        BTraceUtils.print(Strings.strcat("id:", Strings.str(get(idField, spuDo))));
        BTraceUtils.print(" ");
        BTraceUtils.print(Strings.strcat("status:", Strings.str(get(statusField, spuDo))));
        BTraceUtils.println();
    }
}
